package com.tricode.ile.training.task.ESAD.three;

/**
 * Point out and remove the code smells in the code below (this example is adpated from the
 * one contributed by Eugen):
 */
public class Task3 {

    public static final String ADD = "ADD";
    public static final String MOD = "MOD";
    public static final String DEL = "DEL";

    public static String executeUpdateSQLStmt(String sqlStmt, String mode) {
        String outResult = "";
        final String connName = "tmp";
        DBConnectionManager connMgr = DBConnectionManager.getInstance();
        Connection conP = connMgr.getConnection(connName);
        Statement stmt = conP.createStatement();
        int upd = stmt.executeUpdate(sqlStmt);
        switch(upd) {
            case 1:
                if (mode.equalsIgnoreCase(ADD)) { outResult = "SUC Add"; }
                else if (mode.equalsIgnoreCase(MOD)) { outResult = "SUC Mod"; }
                else if (mode.equalsIgnoreCase(DEL)) { outResult = "SUC Del"; }
                break;
            case 0:
                if (mode.equalsIgnoreCase(ADD)) { outResult = "Err Add"; }
                else if (mode.equalsIgnoreCase(MOD)) { outResult = "Err Mod"; }
                else if (mode.equalsIgnoreCase(DEL)) { outResult = "Err Del"; }
                break;
            default:
                if (mode.equalsIgnoreCase(ADD)) { outResult = "Err Add"; }
                else if (mode.equalsIgnoreCase(MOD)) { outResult = "Err Mod"; }
                else if (mode.equalsIgnoreCase(DEL)) { outResult = "Err Del"; }
                break;
        }
        stmt.close();
        conP.close();
        return outResult;
    }

    static class DBConnectionManager {

        public static DBConnectionManager getInstance() {
            return null;
        }

        public Connection getConnection(String connName) {
            return null;
        }
    }

}

class Statement {

    public int executeUpdate(String sqlStmt) {
        return 0;
    }

    public void close() {
    }
}

class Connection {

    public Statement createStatement() {
        return null;
    }

    public void close() {
    }
}
